//
//  MainViewController.m
//  AppSettings
//
//  Created by KaiKai on 11-8-13.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MainViewController.h"

@implementation MainViewController

@synthesize usernameLabel;
@synthesize passwordLabel;
@synthesize protocolLabel;
@synthesize warpDriveLabel;
@synthesize warpFactorLabel;

@synthesize favoriteTeaLabel;
@synthesize favoriteCandyLabel;
@synthesize favoriteGameLabel;
@synthesize favoriteExcuseLabel;
@synthesize favoriteSinLabel;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
	[self refreshFields];
}

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showInfo:(id)sender
{    
    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    controller.delegate = self;
    
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
    
    [controller release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (IBAction)refreshFields
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	usernameLabel.text = [defaults objectForKey:KUsernameKey];
	passwordLabel.text = [defaults objectForKey:KPasswordKey];
	protocolLabel.text = [defaults objectForKey:KProtocolKey];
	warpDriveLabel.text = [defaults objectForKey:KWarpDriveKey];
	warpFactorLabel.text = [[defaults objectForKey:KWarpFactorKey] stringValue];
	
	favoriteTeaLabel.text = [defaults objectForKey:KFavoriteTeaKey];
	favoriteCandyLabel.text = [defaults objectForKey:KFavoriteCandyKey];
	favoriteGameLabel.text = [defaults objectForKey:KFavoriteGameKey];
	favoriteExcuseLabel.text = [defaults objectForKey:KFavoriteExcuseKey];
	favoriteSinLabel.text = [defaults objectForKey:KFavoriteSinKey];
}

- (void)viewDidAppear:(BOOL)animated
{
	[self refreshFields];
	[super viewDidAppear:animated];
}

- (void)dealloc
{
	[usernameLabel release];
	[passwordLabel release];
	[protocolLabel release];
	[warpDriveLabel release];
	[warpFactorLabel release];
	
	[favoriteTeaLabel release];
	[favoriteCandyLabel release];
	[favoriteGameLabel release];
	[favoriteExcuseLabel release];
	[favoriteSinLabel release];
	
	[super dealloc];
}

@end
